/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BeansGerenciaveis;

import bean.Autor;
import java.io.Serializable;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author fernando
 */
public class ProfessoresDataModel extends ListDataModel<Autor> implements SelectableDataModel<Autor> {
    
    public ProfessoresDataModel() {  
    }  
  
    public ProfessoresDataModel(List<Autor> data) {  
        super(data);  
    }  
      
    
    public Autor getRowData(int rowKey) {  
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data  
          
        List<Autor> autores = (List<Autor>) getWrappedData();  
          
        for(Autor autor : autores) {  
            if(autor.getId()==rowKey)  
                return autor;  
        }  
          
        return null;  
    }  
  
     
    public Object getRowKey(Autor autor) {  
        return autor;  
    }  

    @Override
    public Autor getRowData(String string) {
        List<Autor> autores = (List<Autor>) getWrappedData();  
        int rowKey = Integer.parseInt(string);  
        for(Autor autor : autores) {  
            if(autor.getId()==rowKey){
                return autor;
            }  
                  
        }  
          
        return null;  
    }
    
}
